package com.pig4cloud.pig.mt.manage;

import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.mt.entity.WxAccount;
import com.pig4cloud.pig.mt.service.WxAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 公众号账号
 *
 * @author niefy
 * @date 2020-06-17 13:56:51
 */
@RestController
@RequestMapping("/manage/wxAccount")
@Api(value = "/manage/wxAccount", tags = "公众号账号管理")
public class WxAccountManageController {
    @Autowired
    private WxAccountService wxAccountService;

    /**
     * 列表
     */
	@ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/list")
	@PreAuthorize("@pms.hasPermission('mt_wxaccount_get')" )
    public R list() {
        List<WxAccount> list = wxAccountService.list();

        return R.ok(list);
    }


    /**
     * 信息
     */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/info/{appid}")
	@PreAuthorize("@pms.hasPermission('mt_wxaccount_get')" )
    public R info(@PathVariable("id") String appid) {
        WxAccount wxAccount = wxAccountService.getById(appid);

        return R.ok(wxAccount);
    }

    /**
     * 保存
     */
	@ApiOperation(value = "新增公众号账号", notes = "新增公众号账号")
	@SysLog("新增公众号账号" )
    @PostMapping("/save")
	@PreAuthorize("@pms.hasPermission('mt_wxaccount_add')" )
    public R save(@RequestBody WxAccount wxAccount) {
        wxAccountService.save(wxAccount);

        return R.ok();
    }

    /**
     * 删除
     */
	@ApiOperation(value = "通过id删除公众号账号", notes = "通过id删除公众号账号")
	@SysLog("通过id删除公众号账号" )
    @DeleteMapping("/delete")
	@PreAuthorize("@pms.hasPermission('mt_wxaccount_del')" )
    public R delete(@RequestBody String[] appids) {
        wxAccountService.removeByIds(Arrays.asList(appids));

        return R.ok();
    }

}
